<%--
  User: 黄星
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/page/admin/static/h-ui/css/H-ui.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet"
          type="text/css"/>
    <link href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/style.css" rel="stylesheet"
          type="text/css"/>
    <link href="${pageContext.request.contextPath}/page/admin/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet"
          type="text/css"/>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/jquery.sPage.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery.sPage.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/layer/2.4/layer.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/page/admin/lib/webuploader/0.1.5/webuploader.min.js"></script>

    <script type="text/javascript">

        function revoveryQuestionByQuery(){
            var ele = $(".checkbox"); //获取所以复选框对象
            var list = [];
            $.each(ele,function(index,value){
                if($(this).is(':checked')){ //如果复选框被选中
                    list[list.length] = $(this).parent().next().text(); //填进数组
                }
            });
            alert(JSON.stringify(list));
            if(0==list.length){
                layer.msg('至少选择一个题目',{icon:5,time:2000});
            } else {
                //先询问是否删除
                if(confirm('您确定要恢复吗?')){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/QuestionManage/recoveryQuestionByQuery",
                        type:"get",
                        dataType:"json",

                        data:{"questionIdList":JSON.stringify(list)},//学生ID列表
                        success:function(data){
                            if(1==data.res){
                                layer.msg('恢复成功',{icon:1,time:2000});
                                location.reload();
                            }

                        },
                        error:function(){
                            alert('error');
                        }

                    });
                }
            }
        }

        /*恢复题目*/
        function question_recovery(questionId){
            $.ajax({
                url: "${pageContext.request.contextPath}/QuestionManage/questionRecovery",
                type: "post",
                dataType: "text",
                data:"questionId=" + questionId,
                success:function (message) {
                    parent.layer.msg(message,{icon:1,time:2000});
                    location.replace(location.href);
                },
                error:function () {
                    alert("error")
                }
            });
        }

        /*初始化函数*/
        $(function () {
            typeSelect();
            majorSelect();
            classesSelect();
            subjectSelect();
            showQuestion(1, 10, 0, 0, 0, 0);
        });

        function showQuestion(page, pageSize, majorId, gradeId, subjectId, typeId) { //点击分页按显示学生信息
            $.ajax({
                url: "${pageContext.request.contextPath}/QuestionManage/getDelQuestionByPaging",
                type: "get",
                dataType: "json",
                data: {
                    "page": page,
                    "pageSize": pageSize,
                    "majorId": majorId,
                    "gradeId": gradeId,
                    "subjectId": subjectId,
                    "typeId": typeId
                },
                async: false,
                success: function (paging) {
                    $("#tbody").html("");
                    $.each(paging.list, function (index, question) {
                        $("#tbody").append(
                            '<tr class="text-c">' +
                            '<td><input class="checkbox" type="checkbox" name=""></td>'+
                            '<td>' + question.id + '</td>' +
                            '<td>' + question.subject.subjectName + '</td>' +
                            '<td>' + question.type.typeName + '</td>' +
                            '<td>' + question.topic + '</td>' +
                            '<td><a style="text-decoration:none" class="ml-5" onclick="question_recovery(' + question.id + ')" title="恢复">' +
                            '<i class="Hui-iconfont">&#xe6df;</i></a>' +
                            '</tr>'
                        );
                    });
                    if (paging.list.length == 0) {
                        //长度为0 就隐藏分页栏
                        $("#myPage").css("display", "none");
                    } else {
                        $("#myPage").css("display", "block");
                        sPageInit(paging.totalCount, paging.currentPage, paging.pageSize, paging.totalPage, majorId, gradeId, subjectId, typeId); //填充分页条信息
                    }
                },
                error: function () {
                    alert('error');
                }
            });
        }

        function sPageInit(total, page, pageSize, pageCount, majorId, gradeId, subjectId, typeId) { //page当前页，total总条数，pageSize页面大小
            $("#myPage").sPage({ //对分页条进行数据填充
                page: page,//当前页码，必填
                total: total,//数据总条数，必填
                pageSize: pageSize,//每页显示多少条数据，默认10条
                showTotal: true,//是否显示总条数，默认关闭：false
                totalTxt: '共' + total + '条',//数据总条数文字描述，{total}为占位符，默认"共{total}条" //可以不要
                showSkip: true,//是否显示跳页，默认关闭：false
                showPN: true,//是否显示上下翻页，默认开启：true
                prevPage: "上一页",//上翻页文字描述，默认“上一页”
                nextPage: "下一页",//下翻页文字描述，默认“下一页”
                backFun: function (page) {
                    showQuestion(page, pageSize, majorId, gradeId, subjectId, typeId);
                }
            });
        }

        function majorSelect() {
            $("#majorSelect").change(function () {
                var majorId = $("#majorSelect option:selected").val();
                if (0 == majorId) {
                    //选择第一个选项，无反应
                    $("#classesSelect").empty();
                    $("#classesSelect").append(
                        '<option value=0>请选择年级</option>'
                    );
                    $("#subjectSelect").empty();
                    $("#subjectSelect").append(
                        '<option value=0>请选择科目</option>'
                    );
                    $("#typeSelect").empty();
                    $("#typeSelect").append(
                        '<option value=0>请选择题型</option>'
                    );
                } else {
                    $("#classesSelect").empty();
                    $("#classesSelect").append(
                        '<option value=0>请选择年级</option>'
                    );
                    $("#classesSelect").append(
                        '<option value=1>大一</option>'
                    );
                    $("#classesSelect").append(
                        '<option value=2>大二</option>'
                    );
                    $("#classesSelect").append(
                        '<option value=3>大三</option>'
                    );
                    $("#classesSelect").append(
                        '<option value=4>大四</option>'
                    );
                    $("#classesSelect").val(0);
                    $("#subjectSelect").empty();
                    $("#subjectSelect").append(
                        '<option value=0>请选择科目</option>'
                    );
                    $("#subjectSelect").val(0);
                    $("#typeSelect").val(0);
                }
                search();
            });
        }

        function classesSelect() {
            $("#classesSelect").change(function () {
                /*获取专业 和  年级ID  以查询科目*/
                var majorId = $("#majorSelect option:selected").val();
                var gradeId = $("#classesSelect option:selected").val();
                $.ajax({
                    url: "${pageContext.request.contextPath}/QuestionManage/getSubjectByMajorAndClasses",
                    type: "get",
                    dataType: "json",
                    data: {"majorId": majorId, "gradeId": gradeId},
                    async: false,
                    success: function (paging) {
                        $("#tbody").html("");

                        $("#subjectSelect").empty();
                        $("#subjectSelect").append(
                            '<option value=0>请选择科目</option>'
                        );
                        $.each(paging.list, function (index, subjectList) {
                            $("#subjectSelect").append(
                                '<option value=' + subjectList.id + '> ' + subjectList.subjectName + '</option>'
                            );
                        });
                        $("#subjectSelect").val(0);
                        $("#typeSelect").val(0);
                        search();
                    },
                    error: function () {
                        alert('error');
                    }
                });

            })
        }

        function subjectSelect() {
            $("#subjectSelect").change(function () {
                $("#typeSelect").val(0);
                search();
            })
        }

        function typeSelect() {
            $("#typeSelect").change(function () {
                search();
            });
        }

        /*提取查询方法  每次改变下拉框的值就进行刷星*/
        function search() {
            var majorId = $("#majorSelect option:selected").val();
            var classesId = $("#classesSelect option:selected").val();
            var subjectId = $("#subjectSelect option:selected").val();
            var typeId = $("#typeSelect option:selected").val();

            showQuestion(1, 10, majorId, classesId, subjectId, typeId);
        }
    </script>

</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 题库管理 <span
        class="c-gray en">&gt;</span> 删除题目管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
</div>

<div class="cl pd-5 bg-1 bk-gray mt-20">

    		<span class="l">

 			<a href="javascript:" onclick="revoveryQuestionByQuery()" class="btn btn-danger radius"><i class="icon-trash"></i><i
                    class="Hui-iconfont">&#xe6e2;</i> 批量恢复</a>
        </span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <select id="majorSelect">
        <option value="0">请选择专业</option>
        <c:forEach items="${majorList}" var="major" varStatus="status">
            <option value="${major.id}">${major.majorName}</option>
        </c:forEach>
    </select>

    <select id="classesSelect">
        <option value="0">请选择年级</option>
    </select>

    <select id="subjectSelect">
        <option value="0">请选择科目</option>
    </select>

    <select id="typeSelect">
        <option value="0">请选择题型</option>
        <c:forEach items="${typeList}" var="type">
            <option value="${type.id}">${type.typeName}</option>
        </c:forEach>
    </select>

</div>

<div class="mt-20">
    <table class="table table-border table-bordered table-hover table-bg table-sort">
        <thead>
        <tr class="text-c">
            <th width="25"><input type="checkbox" name="" value=""></th>
            <th width="30">ID</th>
            <th width="130">科目</th>
            <th width="60">题型</th>
            <th width="400">题目</th>
            <th width="50">恢复</th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
    </table>
    <div id="myPage" align="center" class="demo"></div>
    <input id="updFlash" type="button" onclick="search()" style="display: none">
</div>

</body>
</html>
